﻿using lwzlz.Application.System;
using System.Web.Mvc.Filters;

namespace lwzlz.Web
{
    /// <summary>
    /// 后台控制器
    /// </summary>
    public class AdminController : BaseController
    {
        public LoginUser _user { get { return UserAuthentication.GetCurrentUser(); } }
        /// <summary>
        /// 在进行授权时调用
        /// </summary>
        /// <param name="filterContext"></param>
        protected override void OnAuthentication(AuthenticationContext filterContext)
        {
            if (!UserAuthentication.IsLogined())
            {
                filterContext.Result = RedirectToRoute(new { area = "SysAdmin", controller = "Login", action = "Index" });
            }

            base.OnAuthentication(filterContext);
        }
        ///// <summary>
        ///// 异常登录检测
        ///// </summary>
        //protected override void OnActionExecuting(ActionExecutingContext filterContext)
        //{
        //    if (UserAuthentication.IsLogined())
        //    {
        //        Hashtable singleOnline = (Hashtable)filterContext.HttpContext.Application["Online"];
        //        // 判断当前SessionID是否存在
        //        if (singleOnline != null && singleOnline.ContainsKey(_user.UserName))
        //        {
        //            if (!singleOnline[_user.UserName].Equals(filterContext.HttpContext.Session.SessionID))
        //            {
        //                filterContext.Result = new ContentResult() { Content = "<script>alert('您的帐号已在别处登录 ，将被迫下线（请保管好自己的账号密码）！');window.top.location.href='/SysAdmin/login/index'</script>" };
        //            }
        //        }
        //    }
        //    base.OnActionExecuting(filterContext);
        //}
    }
}